/**
 * 分页(葛晓鹏)2012-12-7
 */
var pagination = {
  getPaginationHtml: function(url, currentPage, count, divid) {

    if (currentPage < 1) {
      currentPage = 1;
    }
    if (currentPage > count) {
      currentPage = count;
    }
    if (url == null || url == "" || url.length == 0)
      return "";
    if (count <= 0) {
      return "";
    }
    var span = 2;
    var si = 0;
    var ei = 0;
    si = Math.max(1, currentPage - span);
    ei = Math.min(count, currentPage + span);
    if (ei == count) {
      if (count - 2 * (span + 1) > 1) {
        si = count - 2 * (span + 1) + 1;
        if (si < 3) {
          si = 3
        }
      }
    }
    if (si == 2) {
      si = 1;
    }
    if (si == 1) {
      if ((span + 1) * 2 >= count) {
        ei = count;
      } else {
        ei = (span + 1) * 2;
      }
    }

    if (ei == count - 1) {
      ei = count;
    }

    var s = "";
    if (currentPage > 1) {
      s += "<a class=\"rfirst\" href=\"" + url.replace("{0}", 1) + "\" ></a>";
      s += "<a class=\"rprev\" href=\"" + url.replace("{0}", currentPage - 1) + "\" ></a></a>";
    } else {
      s += "<span class=\"first\"></span><span class=\"prev\"></span>";
    }
    if (currentPage - span >= 3) {
      s += "<a  class=\"numbg\" href=\"" + url.replace("{0}", 1) + "\" >1</a> ";
      //alert(si+"|"+ei);
      if (si > 2) {
        s += "<a  class=\"numbgx\">&hellip;</a>";
      }
    }



    //补齐数量
    if (si > 2) {
      //s += "<a    class=\"numbg\" href=\"" + url.replace("{0}",(si-1))+ "\" >" + (si-1)+ "</a> ";	
    }
    for (var i = si; i <= ei; i++) {
      if (i == currentPage) {
        s += "<a class=\"numbgs\">" + i + "</a>";
      } else {
        s += "<a  class=\"numbg\" href=\"" + url.replace("{0}", i) + "\" >" + i + "</a> ";
      }

    }
    if (ei < count) {
      s += "<a  class=\"numbgx\">&hellip;</a>";
      s += "<a class=\"numbg\" href=\"" + url.replace("{0}", count) + "\" >" + count + "</a> ";
    }
    if (currentPage < count) {
      s += "<a class=\"rnext\" href=\"" + url.replace("{0}", currentPage + 1) + "\" ></a>";
      s += "<a class=\"rlast\" href=\"" + url.replace("{0}", count) + "\" ></a>";
    } else {
      s += "<span class=\"next\"></span><span class=\"last\"></span>";
    }

    if (divid != null && divid != '') {
      //alert(document.getElementById(divid));
      $("#" + divid).html(s);
      //document.getElementById(divid).innerHTML=s;
      //alert(s);
      //set_innerHTML(divid,s);
    } else {
      set_innerHTML("pagination", s);
      //document.getElementById("pagination").innerHTML=s;
    }
  }

}
